package com.douhl.project.business.visitor.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.douhl.framework.aspectj.lang.annotation.Log;
import com.douhl.framework.aspectj.lang.enums.BusinessType;
import com.douhl.project.business.visitor.domain.BusinessVisitor;
import com.douhl.project.business.visitor.service.IBusinessVisitorService;
import com.douhl.framework.web.controller.BaseController;
import com.douhl.framework.web.domain.AjaxResult;
import com.douhl.common.utils.poi.ExcelUtil;
import com.douhl.framework.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 访客记录Controller
 *
 * @author douhl
 * @date 2020-08-18
 */
@Api("访客记录表")
@RestController
@RequestMapping("/business/visitor")
public class BusinessVisitorController extends BaseController
{
    @Autowired
    private IBusinessVisitorService businessVisitorService;

    /**
     * 查询访客记录列表
     */
    @ApiOperation("查询访客记录列表")
    @ApiImplicitParam(name = "businessVisitor", value = "访客记录表", required = true, dataType = "BusinessVisitor", paramType = "query")
    @PreAuthorize("@ss.hasPermi('business:visitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessVisitor businessVisitor)
    {
        startPage();
        List<BusinessVisitor> list = businessVisitorService.selectBusinessVisitorList(businessVisitor);
        return getDataTable(list);
    }

    /**
     * 导出访客记录列表
     */
    @ApiOperation("导出访客记录列表")
    @ApiImplicitParam(name = "businessVisitor", value = "访客记录表", required = true, dataType = "BusinessVisitor", paramType = "query")
    @PreAuthorize("@ss.hasPermi('business:visitor:export')")
    @Log(title = "访客记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessVisitor businessVisitor)
    {
        List<BusinessVisitor> list = businessVisitorService.selectBusinessVisitorList(businessVisitor);
        ExcelUtil<BusinessVisitor> util = new ExcelUtil<BusinessVisitor>(BusinessVisitor.class);
        return util.exportExcel(list, "visitor");
    }

    /**
     * 获取访客记录详细信息
     */
    @ApiOperation("获取访客记录详细信息")
    @ApiImplicitParam(name = "id", value = "访客记录ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('business:visitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessVisitorService.selectBusinessVisitorById(id));
    }

    /**
     * 新增访客记录
     */
    @ApiOperation("新增访客记录")
    @ApiImplicitParam(name = "businessVisitor", value = "访客记录表", required = true, dataType = "BusinessVisitor", paramType = "body")
    @PreAuthorize("@ss.hasPermi('business:visitor:add')")
    @Log(title = "访客记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessVisitor businessVisitor)
    {
        return toAjax(businessVisitorService.insertBusinessVisitor(businessVisitor));
    }

    /**
     * 修改访客记录
     */
    @ApiOperation("修改访客记录")
    @ApiImplicitParam(name = "businessVisitor", value = "访客记录表", required = true, dataType = "BusinessVisitor", paramType = "query")
    @PreAuthorize("@ss.hasPermi('business:visitor:edit')")
    @Log(title = "访客记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessVisitor businessVisitor)
    {
        return toAjax(businessVisitorService.updateBusinessVisitor(businessVisitor));
    }

    /**
     * 删除访客记录
     */
    @ApiOperation("删除访客记录")
    @ApiImplicitParam(name = "ids", value = "访客记录ids", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('business:visitor:remove')")
    @Log(title = "访客记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessVisitorService.deleteBusinessVisitorByIds(ids));
    }
}
